package com.wanyang.service.impl;

import com.wanyang.dao.AccountDao;
import com.wanyang.pojo.Cloud;
import com.wanyang.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhai on 16/4/18.
 */
@Service
public class AccountServiceImpl implements AccountService {

    private AccountDao accountDao;

    @Autowired
    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public List<Cloud> getAccountList(Integer userId) {
        return accountDao.getAccountList(userId);
    }

    @Override
    public Integer deleteCloud(Integer cloudId) {
        return accountDao.delete(accountDao.fetch(cloudId));
    }

    @Override
    public Cloud getById(Integer cloudId) {
        return accountDao.fetch(cloudId);
    }

    @Override
    public Boolean save(Cloud cloud, Integer editType) {
        if(editType == 0) {
            return null != accountDao.create(cloud);
        } else {
            return accountDao.update(cloud) > 0;
        }
    }
}
